-- slime_damage
-- create by wangy
-- 单体攻击（专属用）

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 专属技能等级
        local level;
        local prop;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        -- 威力
        local force = para[2];

        -- 攻击方的攻击
        local attack = source:getAttack();

        -- 伤害
        local damage = math.modf(attack * (force + level * 500) / 1000);

        -- 伤害提升
        prop = PropM.combine(source, "skill_force_add", skillId);
        if prop[3] > 0 then
            damage = PropM.apply(prop, damage);
        end

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end
        damage = PropM.apply(prop, damage);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 如果是玩家，抛出攻击结果事件
        if source.type == OBJECT_TYPE_USER then
            EventMgr.fire(event.HERO_ATTACK_RESULT, { ["damage"] = damage, ["extra"] = extra});
        end

        -- 如果受攻击对象是怪物，抛出投掷类攻击事件
        if target.type == OBJECT_TYPE_MONSTER then
            -- 播放特效所需的参数
            local effectInfo = {
                ["move_type"] = para[3],
                ["effect_id"] = para[4],
                ["tail_id"] = para[5] ~= 0 and para[5] or nil,
                ["offset"] = cc.p(para[6], para[7]),
                ["pos"] = target:getOwner();
                ["icon_id"] = 3058;
            };

            -- 抛出投掷类攻击事件
            EventMgr.fire(event.SKILL_ATTACK, { ["effect_info"] = effectInfo, });
        end

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), arr[3], tonumber(arr[4]), tonumber(arr[5]), tonumber(arr[6]), tonumber(arr[7]) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 威力
        local force = para[2];

        -- 攻击方的攻击
        local attack = source:getAttack();

        -- 伤害
        local damage = math.modf(attack * (force + level * 500) / 1000);

        -- 伤害提升
        prop = PropM.combine(source, "skill_force_add", skillId);
        if prop[3] > 0 then
            damage = PropM.apply(prop, damage);
        end

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        damage = PropM.apply(prop, damage);

        desc = string.gsub(desc, "{slime_damage}", damage);

        return desc;
    end,
};
